﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using NJ.Dto.RoleMenu;
@{
    var list = Model as List<MenuDto>;
}

<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">所属父级</label>
        <div class="layui-form-mid layui-word-aux">
            @{

                if (list.Count > 0)
                {
                    <span class="layui-breadcrumb" style="padding-left: 10px;">
                        @foreach (var item in list)
                        {
                            <a href="javascript:;;">@item.Title</a>
                        }
                    </span>
                }
                else
                {
                    <span class="layui-breadcrumb" style="padding-left: 10px;">
                        <a href="javascript:;;">顶级</a>
                    </span>
                }
            }
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input" />
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">Url</label>
            <div class="layui-input-inline">
                <input type="tel" name="url" placeholder="请输入Url" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">图标</label>
            <div class="layui-form-mid layui-word-aux">
                <i class="layui-icon font24" id="icon" style="margin-left:10px">&#xe61f;</i>
                <input type="hidden" name="icon" autocomplete="off" class="layui-input" value="">
            </div>
        </div>
    </div>
    <input type="hidden" name="pid" value="@Request.QueryString["Pid"]" />

    <div class="layui-form-item" style="display:none">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="save" id="save">立即提交</button>
        </div>
    </div>
</form>

@section scripts{
    <script>
        layui.use(['element', 'form'], function () {
            var $ = layui.$;
            var layer = parent.layer;
            var form = layui.form;
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

            //监听提交
            form.on('submit(save)', function (data) {
                $.post('/Menu/SaveAsync', data.field, function (res) {
                    if (res.status === 200) {
                        parent.GetMenus();
                        parent.layer.close(index);
                        parent.layer.msg('添加成功', { time: 800 });
                    } else {
                        layer.msg('操作失败', { time: 800 });
                    }
                })
                return false;
            });
            $('#icon').click(function () {
                layer.open({
                    type: 2,
                    area: ['700px', '500px'],
                    shade: 0.4,
                    title: '选中图标',
                    content: '/StaticPage/Icons.html',
                    btn: ['确定', '取消'],
                    yes: function (index, layero) {
                        var body = layer.getChildFrame('body', index);
                        var icon = body.find('.checked .doc-icon-code').text();
                        if (icon) {
                            $('#icon').html(icon);
                            $('input[name=icon]').val(icon);
                        }
                        layer.close(index);
                    }
                });
            })
        });
    </script>
}